#define _CRT_SECURE_NO_WARNINGS

#include"stack.h"

void test()
{
	Stack s;
	StackInit(&s);
	StackPush(&s, 1);
	StackPush(&s, 2);
	StackPush(&s, 3);
	StackPush(&s, 4);
	StackPop(&s);
	StackPop(&s);
	StackPop(&s);
	int sz = StackSize(&s);

	printf("%d\n", StackTop(&s));

	StackDestroy(&s);
}

bool isValid(char* s)
{
    Stack st;
    StackInit(&st);
    char* cur = s;
    while (*cur)
    {
        if (*cur == '(' || *cur == '{' || *cur == '[')
        {
            StackPush(&st, *cur);
        }
        else
        {
            if (StackEmpty(&st))
            {
                StackDestroy(&st);
                return false;
            }
            char tmp = StackTop(&st);
            StackPop(&st);
            if ((*cur == ')' && tmp != '(')
                || (*cur == ']' && tmp != ']')
                || (*cur == '}' && tmp != '{'))
            {
                StackDestroy(&st);
                return false;
            }
        }
        cur++;
    }
    if (!StackEmpty(&st))
    {
        StackDestroy(&st);
        return false;
    }
    StackDestroy(&st);
    return true;
}





int main()
{

    char a[] = "()[]{}";

    isValid(a);

	return 0;
}